$NG.AllReady(function (page, { useAction, useBeforeClick, useValuesChange, useClick, useUpdateRow, subscribe, useUpdateRows }) {
    const mstform = $NG.getCmpApi("CntPayMForm")
    const dgrid1 = $NG.getCmpApi("")
    const getHeadValue = (str) => mstform.getItem(str).getValue()
    console.log(`page`, page, page.isList);
    const list = $NG.getCmpApi("CntPayM")
    const url = `${location.href}`
    setTimeout(() => {
        const param = parseUrlParams(url)
        const keys = Object.keys(param)
        console.log(`keys`, keys);
        if (!param.AppTitle.includes("-")) {
            if (keys.includes('cnt_id')) {
                if (param.cnt_id == 'add') {
                    param.cnt_id = 0
                }
                console.log(`列表页面`,);
                list.getItem("PhidCnt*int64*eq*1").setValue({
                    label: param.cnt_name,
                    value: param.cnt_id
                })
                setTimeout(() => {
                    list.submit()
                }, 200)
            }
        }
        hiddenDetail(['RewardTable', 'DeductionTable'])
    }, 200)

    useValuesChange(() => {
        const PhidCnt = mstform.getItem("PhidCnt").getValue()
        if (!PhidCnt) return
        $NG.execServer("getCntCbInfoByPhid", { phid: PhidCnt }, (res) => {
            if (res.count == 0) {
                return
            }
            const datas = JSON.parse(res.data)[0].extendObjects
            console.log(`datas`, datas);
            const arr = [

                {
                    key: 'user_jfdw',
                    value: {
                        value: datas.jfdw_phid,
                        label: datas.jfdw_name
                    }
                },
                {
                    key: 'user_htje',
                    value: datas.user_htje
                },
            ]
            setHeadValues(arr)
        })

    }, "PhidCnt")

    // 表头批量赋值
    function setHeadValues(arr) {
        arr.forEach(item => {
            mstform.getItem(item.key)?.setValue(item.value)
        })
    }

    // 隐藏系统表单的明细标签
    function hiddenDetail(detailKey) {
        const page = detailKey.reduce((value, item) => {
            value.push($NG.getCmpApi(item))
            return value
        }, [])
        // 开始隐藏
        page.forEach(docker => {
            if (docker) {
                const bigDom = docker.getRef().bodyRef.current
                //向上查找父元素是否存在，向上查找3级
                let temp_pNode = bigDom.parentNode
                let pNode = null
                for (let level = 0; level < 9; level++) {
                    if (temp_pNode && temp_pNode.className?.replaceAll(" ", "") == 'udp-full-page') {
                        pNode = temp_pNode
                        break
                    }
                    temp_pNode = temp_pNode.parentNode
                    console.log(`temp`, temp_pNode, temp_pNode.className);
                }
                if (pNode) {
                    pNode.style.display = 'none'
                } else {
                    console.log(`没找到`, page);
                }
            }
        })
    }


    // 解析URL  
    function parseUrlParams(url) {
        const result = {};

        if (!url) return result;

        // 先拆出 ? 和 #
        const [beforeHash, hashPart] = url.split('#');

        // 处理 ? 部分
        if (beforeHash.includes('?')) {
            const queryStr = beforeHash.split('?')[1];
            queryStr.split('&').forEach(pair => {
                const [key, value] = pair.split('=');
                result[key] = decodeURIComponent(value || '');
            });
        }

        // 处理 # 后面的参数
        if (hashPart && hashPart.includes('?')) {
            const hashQueryStr = hashPart.split('?')[1];
            hashQueryStr.split('&').forEach(pair => {
                const [key, value] = pair.split('=');
                result[key] = decodeURIComponent(value || '');
            });
        }

        return result;
    }
}, function () {

})